<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<button>测试1</button>
		<button>测试2</button>
		<button>测试3</button>
		
		<script>
			"use strict" 
			
			let username = "kobe"
//			let username = "kobe"
			console.log(username)
			
			let btns = document.getElementsByTagName("button")
			for (let i = 0; i < btns.length; i++) {
				let btn = btns[i];
				btn.onclick = function(){
					alert(i)
				}
			}
//			闭包
//			for (var i = 0; i < btns.length; i++) {
//				var btn = btns[i];
//				(function(i){
//					btn.onclick = function(){
//						alert(i)
//					}
//				})(i)
//			}

		</script>
	</body>
</html>
